package com.quwan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quwan.app.vo.RecommendMemberDTO;
import com.quwan.entity.TMemberRecommend;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author laozhang
 * @date 2022-02-16
 */


public interface TMemberRecommendMapper extends BaseMapper<TMemberRecommend> {
    /*@Select("select m.id mId,m.img_url,mr.label category from " +
            "t_member_recommend mr left  join t_member m on  mr.m_id= m.auto_id " +
            "where m.status = 1 order by  mr.sort")*/
    @Select({"<script>",
            " select m.id mId,m.img_url,m.area,m.last_visit_time,m.nick_name,mr.label category ," +
                    "(select count(1) from t_member_vip as v where v.m_id =m.id and v.end_time > now()) as vip " +
                    "from ",
            " t_member_recommend mr left  join t_member m on mr.m_id=m.auto_id ",
            " where m.status =1 ",
            " <if test='gender != null '>",
            " and m.gender= #{gender}",
            "</if>",
            " <if test='age != null'>",
            " and m.age <![CDATA[ <= ]]> #{age}",
            " </if>",
            " order by ",
            " <trim prefixOverrides=',' suffixOverrides=''>",
            "<if test='auto != null' >",
            " mr.add_time desc ",
            "</if>",
            " ,  mr.sort",
            "</trim>",
            "</script>"})
    Page<RecommendMemberDTO> selectRecommendList(Page<Object> objectPage,
                                                 @Param("auto") String auto,
                                                 @Param("gender") String gender,
                                                 @Param("age") Integer age);
}